//
//  MVP_TableViewCell.m
//  MVC|MVP|MVVM
//
//  Created by Guo Rui on 2017/11/14.
//  Copyright © 2017年 GR Harry. All rights reserved.
//

#import "MVP_TableViewCell.h"
#import <UIImageView+WebCache.h>

@interface MVP_TableViewCell()
@property (weak, nonatomic) IBOutlet UIButton *comentButton;
@property (weak, nonatomic) IBOutlet UIButton *likeButton;
@property (weak, nonatomic) IBOutlet UILabel *infoLabel;
@property (weak, nonatomic) IBOutlet UIImageView *albumView;
@property (weak, nonatomic) IBOutlet UILabel *contentLabel;

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *imageView_height_constraint;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *imageView_width_constraint;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *imageView_top_constraint;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *contentLabel_top_constraint;


@end

@implementation MVP_TableViewCell

- (IBAction)likeButtonDidClick:(id)sender {
    if (self.clickZan) {
        self.clickZan();
    }
}

- (void)setImageURL:(NSString *)imageUrl
{
    if (imageUrl) {
        [self.albumView sd_setImageWithURL:[NSURL URLWithString:imageUrl]];
    }
    else {
        self.albumView.image = nil;
    }
}
- (void)setTimelineContent:(NSString *)content
{
    self.contentLabel.text = content;
}

- (void)setPublishInfo:(NSString *)publishInfo
{
    self.infoLabel.text = publishInfo;
}

- (void)setLike:(BOOL)isLike
{
    self.likeButton.selected = isLike;
}

- (void)setLikeCount:(NSInteger)likeCount
{
    [self.likeButton setTitle:[NSString stringWithFormat:@"%zd", likeCount] forState:UIControlStateNormal];
    [self.likeButton setTitle:[NSString stringWithFormat:@"%zd", likeCount] forState:UIControlStateSelected];
}

- (void)setCommentCount:(NSInteger)commentCount
{
    [self.comentButton setTitle:[NSString stringWithFormat:@"%zd", commentCount] forState:UIControlStateNormal];
    [self.comentButton setTitle:[NSString stringWithFormat:@"%zd", commentCount] forState:UIControlStateSelected];
}

- (void)updateImageViewConstraintWithSize:(CGSize)size
{
    CGFloat w = size.width;
    CGFloat h = size.height;
    
    self.imageView_width_constraint.constant = w;
    self.imageView_height_constraint.constant = h;
}

- (void)hiddenImageView:(BOOL)hidden
{
    if (hidden) {
        self.imageView_height_constraint.constant = 0;
        self.imageView_top_constraint.constant = 0;
    }
    else {
        self.imageView_top_constraint.constant = 10;
    }
}

- (void)hiddenTimelineContentLabel:(BOOL)hidden
{
    self.contentLabel_top_constraint.constant = hidden ? 0 : 20;
    
}

@end
